package com.example.administrator.daydayappmarket.list.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.daydayappmarket.R;
import com.example.administrator.daydayappmarket.list.model.ListSolftItem;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * User: 东哥哥
 * Date: 2016/12/26
 * Time: 15:46
 * Project: DayDayAppMarket
 * Describe：
 */


public class ListSolftAdapter extends BaseAdapter {

    private Context context;
    private List<ListSolftItem> data;

    public ListSolftAdapter(Context context, List<ListSolftItem> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public ListSolftItem getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder=null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_list_solft, parent, false);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);

        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        String path="http://img.ttigame.com";

        ListSolftItem item = getItem(position);
        viewHolder.itemLsitSolftTextview0.setText(position+4+"");

        String imageUrl=item.getIcon_url();
        if (imageUrl.startsWith("h",0)) {
            Glide.with(context).load(item.getIcon_url()).into(viewHolder.itemLsitSolftIamgeview);
        }else {
            Glide.with(context).load(path+item.getIcon_url()).into(viewHolder.itemLsitSolftIamgeview);
        }

        viewHolder.itemLsitSolftTextview1.setText(item.getName());
        int i = Integer.parseInt(item.getDownload_count());
        double v = ((double) (i / 1000)) / 10.0;
        viewHolder.itemLsitSolftTextview2.setText(v+"万人下载");
        int i1 = Integer.parseInt(item.getPackage_size());
        double v3 = ((int) (((double) i1) / 1024.0 / 1024.0 * 100.0)) / 100.0;
        viewHolder.itemLsitSolftTextview3.setText("  "+v3+"MB");
        viewHolder.itemLsitSolftTextview4.setText(item.getReviews());

        return convertView;
    }


    static class ViewHolder {
        @InjectView(R.id.item_lsit_solft_textview0)
        TextView itemLsitSolftTextview0;
        @InjectView(R.id.item_lsit_solft_iamgeview)
        ImageView itemLsitSolftIamgeview;
        @InjectView(R.id.item_lsit_solft_textview1)
        TextView itemLsitSolftTextview1;
        @InjectView(R.id.item_lsit_solft_textview2)
        TextView itemLsitSolftTextview2;
        @InjectView(R.id.item_lsit_solft_textview3)
        TextView itemLsitSolftTextview3;
        @InjectView(R.id.item_lsit_solft_textview4)
        TextView itemLsitSolftTextview4;
        @InjectView(R.id.item_lsit_solft_button)
        TextView itemLsitSolftButton;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
